package Model;
import java.util.ArrayList;

/**
 * this class handles a list of persons. both Kunde and Medarbejder
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PersonContainer
{
    private ArrayList<Person> kundelist;
    private ArrayList<Person> medarbejderlist;
    private static PersonContainer instance;

    /**
     * Constructor for objects of class PersonContainer
     */
    private PersonContainer()
    {
        kundelist = new ArrayList<Person>();
        medarbejderlist = new ArrayList<Person>();
    }

    /**
     * this method return instance from PersonContainer if instance null
     * 
     * @param nothing
     * @return instance
     */
    public static PersonContainer getInstance()
    {
        if(instance == null)
        {
            instance = new PersonContainer();
        }
        return instance;
    }

    /**
     * this method can find a Kunde
     * 
     * @param tlfnr
     * @return nothing
     */
    public Person findKunde(int tlfnr)
    {
        int index = 0;
        Person returnperson = null;
        while(kundelist.size() > index)
        {
            Person person = kundelist.get(index);

            if(person.getTlfnr() == (tlfnr))
            {
                returnperson = person;
            }
            index++;

        }
        return returnperson;
    }

    /**
     * this method can remove a Kunde from the list
     * 
     * @param tlfnr
     * @return
     */
    public void removeKunde(int tlfnr)
    {
        kundelist.remove(findKunde(tlfnr));
    }

    /**
     * this method can find a medarbejder object
     * 
     * @param id
     * @return nothing
     */
    public Person findMedarbejder(int id)
    {
        int index = 0;
        Person returnperson = null;
        while(medarbejderlist.size() > index)
        {
            Person person = medarbejderlist.get(index);

            if(person.getId() == (id))
            {
                returnperson = person;
            }
            index++;

        }
        return returnperson;
    }

    /**
     * this method can remove a medarbejder object from the list
     * 
     * @param id
     * @return nothing
     */
    public void removeMedarbejder(int id)
    {
        medarbejderlist.remove(findMedarbejder(id));
    }

    /**
     * this method can add a created Kunde to the list
     * 
     * @param kundelist
     * @return nothing
     */
    public void addKunde(Person kundeList)
    {
        kundelist.add(kundeList);
    }

    /**
     * this method can add a medarbejder to the list
     * 
     * @param medarbejderlist
     * @return nothing
     */
    public void addMedarbejder(Person medarbejderList)
    {
        medarbejderlist.add(medarbejderList);
    }

}
